# -*- coding: utf-8 -*-

import logging
import logging.config
from app.common.config import Config
from app.common.globle_var import GlobleVar
from pymongo import MongoClient

class Init():
    def __init__(self):
        self.initLog()
        self.initMongoDb()

    def initLog(self):
        logging.config.fileConfig('logger.ini')
        logging.debug("logger.ini loaded")

    def initMongoDb(self):
        config = Config('config.ini')
        url = "mongodb://" + config.get('mongodb', 'host') + ":" + config.get('mongodb', 'port')
        dbName = config.get('mongodb', 'dbName')
        logging.debug('mongodb:%s, url:%s', dbName, url)
        client = MongoClient(url)
        GlobleVar.setConn(client[dbName])